; RUN: opt < %s -load /home/user/Research/llvm-2.9-build-eclipse/lib/LLVMmpia.so \
; RUN:    -arraytracking -S -disable-output

; ModuleID = 'comm_time_3.ll'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i386-pc-linux-gnu"

%struct.MPI_Status = type { i32, i32, i32, i32, i32 }
%struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i32, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i32, i32, [40 x i8] }
%struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 }
%struct.ompi_communicator_t = type opaque
%struct.ompi_datatype_t = type opaque
%struct.ompi_predefined_communicator_t = type opaque
%struct.ompi_predefined_datatype_t = type opaque

@ompi_mpi_comm_world = external global %struct.ompi_predefined_communicator_t
@.str = private constant [1 x i8] zeroinitializer, align 1
@.str1 = private constant [40 x i8] c"Before Initialize, p = %d, my_rank = %d\00", align 4
@.str2 = private constant [48 x i8] c"Before if, my_rank = %d, source = %d, dest = %d\00", align 4
@ompi_mpi_float = external global %struct.ompi_predefined_datatype_t
@ompi_mpi_double = external global %struct.ompi_predefined_datatype_t
@.str3 = private constant [25 x i8] c"Message size (floats):  \00", align 1
@.str4 = private constant [6 x i8] c"%10d \00", align 1
@.str5 = private constant [40 x i8] c"io_process = %d, time_array_order = %d\0A\00", align 4
@stdout = external global %struct._IO_FILE*
@.str6 = private constant [25 x i8] c"Avg circuit time (ms):  \00", align 1
@.str7 = private constant [6 x i8] c"%10f \00", align 1
@.str8 = private constant [25 x i8] c"Max circuit time (ms):  \00", align 1
@.str9 = private constant [25 x i8] c"Min circuit time (ms):  \00", align 1
@.str10 = private constant [2 x i8] c"\0A\00", align 1

define i32 @main(i32 %argc, i8** %argv) nounwind {
entry:
  %argc_addr = alloca i32, align 4
  %argv_addr = alloca i8**, align 4
  %x = alloca float*
  %times = alloca double*
  %max_times = alloca double*
  %min_times = alloca double*
  %time_array_order = alloca i32
  %p = alloca i32
  %my_rank = alloca i32
  %io_comm = alloca %struct.ompi_communicator_t*
  %status = alloca %struct.MPI_Status
  %"alloca point" = bitcast i32 0 to i32
  store i32 %argc, i32* %argc_addr
  store i8** %argv, i8*** %argv_addr
  %0 = call i32 @MPI_Init(i32* %argc_addr, i8*** %argv_addr) nounwind
  %1 = call i32 @MPI_Comm_size(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), i32* %p) nounwind
  %2 = call i32 @MPI_Comm_rank(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), i32* %my_rank) nounwind
  %3 = call i32 @MPI_Comm_dup(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.ompi_communicator_t** %io_comm) nounwind
  %4 = load %struct.ompi_communicator_t** %io_comm, align 4
  %5 = call i32 @Cache_io_rank(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.ompi_communicator_t* %4) nounwind
  %6 = load i32* %my_rank, align 4
  %7 = load i32* %p, align 4
  %8 = load %struct.ompi_communicator_t** %io_comm, align 4
  %9 = call i32 (%struct.ompi_communicator_t*, i8*, i8*, ...)* @Cprintf(%struct.ompi_communicator_t* %8, i8* getelementptr inbounds ([1 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([40 x i8]* @.str1, i32 0, i32 0), i32 %7, i32 %6) nounwind
  %10 = load i32* %my_rank, align 4
  call void @Initialize(i32 1000, i32 1000, i32 1000, i32 %10, float** %x, double** %times, double** %max_times, double** %min_times, i32* %time_array_order) nounwind
  %11 = load i32* %my_rank, align 4
  %12 = sub nsw i32 %11, 1
  %13 = load i32* %p, align 4
  %14 = srem i32 %12, %13
  %15 = load i32* %my_rank, align 4
  %16 = add nsw i32 %15, 1
  %17 = load i32* %p, align 4
  %18 = srem i32 %16, %17
  br label %bb13

bb:                                               ; preds = %bb13
  %19 = load i32* %my_rank, align 4
  %20 = load %struct.ompi_communicator_t** %io_comm, align 4
  %21 = call i32 (%struct.ompi_communicator_t*, i8*, i8*, ...)* @Cprintf(%struct.ompi_communicator_t* %20, i8* getelementptr inbounds ([1 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([48 x i8]* @.str2, i32 0, i32 0), i32 %19, i32 %14, i32 %18) nounwind
  %22 = load i32* %my_rank, align 4
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %bb1, label %bb9

bb1:                                              ; preds = %bb
  %24 = load double** %times, align 4
  %25 = getelementptr inbounds double* %24, i32 %i.0
  store double 0.000000e+00, double* %25, align 1
  %26 = load double** %max_times, align 4
  %27 = getelementptr inbounds double* %26, i32 %i.0
  store double 0.000000e+00, double* %27, align 1
  %28 = load double** %min_times, align 4
  %29 = getelementptr inbounds double* %28, i32 %i.0
  store double 1.000000e+06, double* %29, align 1
  br label %bb7

bb2:                                              ; preds = %bb7
  %30 = call double @MPI_Wtime() nounwind
  %31 = load float** %x, align 4
  %32 = bitcast float* %31 to i8*
  %33 = call i32 @MPI_Send(i8* %32, i32 %size.0, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %18, i32 0, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %34 = load float** %x, align 4
  %35 = bitcast float* %34 to i8*
  %36 = call i32 @MPI_Recv(i8* %35, i32 %size.0, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %14, i32 0, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.MPI_Status* %status) nounwind
  %37 = call double @MPI_Wtime() nounwind
  %38 = fsub double %37, %30
  %39 = load double** %times, align 4
  %40 = load double** %times, align 4
  %41 = getelementptr inbounds double* %40, i32 %i.0
  %42 = load double* %41, align 1
  %43 = fadd double %42, %38
  %44 = getelementptr inbounds double* %39, i32 %i.0
  store double %43, double* %44, align 1
  %45 = load double** %max_times, align 4
  %46 = getelementptr inbounds double* %45, i32 %i.0
  %47 = load double* %46, align 1
  %48 = fcmp olt double %47, %38
  br i1 %48, label %bb3, label %bb4

bb3:                                              ; preds = %bb2
  %49 = load double** %max_times, align 4
  %50 = getelementptr inbounds double* %49, i32 %i.0
  store double %38, double* %50, align 1
  br label %bb4

bb4:                                              ; preds = %bb3, %bb2
  %51 = load double** %min_times, align 4
  %52 = getelementptr inbounds double* %51, i32 %i.0
  %53 = load double* %52, align 1
  %54 = fcmp ogt double %53, %38
  br i1 %54, label %bb5, label %bb6

bb5:                                              ; preds = %bb4
  %55 = load double** %min_times, align 4
  %56 = getelementptr inbounds double* %55, i32 %i.0
  store double %38, double* %56, align 1
  br label %bb6

bb6:                                              ; preds = %bb5, %bb4
  %57 = add nsw i32 %test.0, 1
  br label %bb7

bb7:                                              ; preds = %bb6, %bb1
  %test.0 = phi i32 [ 0, %bb1 ], [ %57, %bb6 ]
  %58 = icmp slt i32 %test.0, 2
  br i1 %58, label %bb2, label %bb8

bb8:                                              ; preds = %bb7
  br label %bb12

bb9:                                              ; preds = %bb
  br label %bb11

bb10:                                             ; preds = %bb11
  %59 = load float** %x, align 4
  %60 = bitcast float* %59 to i8*
  %61 = call i32 @MPI_Recv(i8* %60, i32 %size.0, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %14, i32 0, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.MPI_Status* %status) nounwind
  %62 = load float** %x, align 4
  %63 = bitcast float* %62 to i8*
  %64 = call i32 @MPI_Send(i8* %63, i32 %size.0, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %18, i32 0, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %65 = add nsw i32 %test.1, 1
  br label %bb11

bb11:                                             ; preds = %bb10, %bb9
  %test.1 = phi i32 [ 0, %bb9 ], [ %65, %bb10 ]
  %66 = icmp slt i32 %test.1, 2
  br i1 %66, label %bb10, label %bb12

bb12:                                             ; preds = %bb11, %bb8
  %67 = add nsw i32 %size.0, 1000
  %68 = add nsw i32 %i.0, 1
  br label %bb13

bb13:                                             ; preds = %bb12, %entry
  %i.0 = phi i32 [ 0, %entry ], [ %68, %bb12 ]
  %size.0 = phi i32 [ 1000, %entry ], [ %67, %bb12 ]
  %69 = icmp sle i32 %size.0, 1000
  br i1 %69, label %bb, label %bb14

bb14:                                             ; preds = %bb13
  %70 = load double** %min_times, align 4
  %71 = load double** %max_times, align 4
  %72 = load double** %times, align 4
  %73 = load i32* %time_array_order, align 4
  %74 = load i32* %my_rank, align 4
  %75 = load %struct.ompi_communicator_t** %io_comm, align 4
  call void @Print_results(%struct.ompi_communicator_t* %75, i32 %74, i32 1000, i32 1000, i32 1000, i32 %73, i32 2, double* %72, double* %71, double* %70) nounwind
  %76 = call i32 @MPI_Finalize() nounwind
  br label %return

return:                                           ; preds = %bb14
  ret i32 undef
}

declare i32 @MPI_Init(i32*, i8***)

declare i32 @MPI_Comm_size(%struct.ompi_communicator_t*, i32*)

declare i32 @MPI_Comm_rank(%struct.ompi_communicator_t*, i32*)

declare i32 @MPI_Comm_dup(%struct.ompi_communicator_t*, %struct.ompi_communicator_t**)

declare i32 @Cache_io_rank(%struct.ompi_communicator_t*, %struct.ompi_communicator_t*)

declare i32 @Cprintf(%struct.ompi_communicator_t*, i8*, i8*, ...)

declare double @MPI_Wtime()

declare i32 @MPI_Send(i8*, i32, %struct.ompi_datatype_t*, i32, i32, %struct.ompi_communicator_t*)

declare i32 @MPI_Recv(i8*, i32, %struct.ompi_datatype_t*, i32, i32, %struct.ompi_communicator_t*, %struct.MPI_Status*)

declare i32 @MPI_Finalize()

define void @Initialize(i32 %max_size, i32 %min_size, i32 %size_incr, i32 %my_rank, float** %x_ptr, double** %times_ptr, double** %max_times_ptr, double** %min_times_ptr, i32* %order_ptr) nounwind {
entry:
  %"alloca point" = bitcast i32 0 to i32
  %0 = mul i32 %max_size, 4
  %1 = call noalias i8* @malloc(i32 %0) nounwind
  %2 = bitcast i8* %1 to float*
  store float* %2, float** %x_ptr, align 4
  %3 = sub nsw i32 %max_size, %min_size
  %4 = sdiv i32 %3, %size_incr
  %5 = add nsw i32 %4, 1
  store i32 %5, i32* %order_ptr, align 4
  %6 = load i32* %order_ptr, align 4
  %7 = mul i32 %6, 8
  %8 = call noalias i8* @malloc(i32 %7) nounwind
  %9 = bitcast i8* %8 to double*
  store double* %9, double** %times_ptr, align 4
  %10 = load i32* %order_ptr, align 4
  %11 = mul i32 %10, 8
  %12 = call noalias i8* @malloc(i32 %11) nounwind
  %13 = bitcast i8* %12 to double*
  store double* %13, double** %max_times_ptr, align 4
  %14 = load i32* %order_ptr, align 4
  %15 = mul i32 %14, 8
  %16 = call noalias i8* @malloc(i32 %15) nounwind
  %17 = bitcast i8* %16 to double*
  store double* %17, double** %min_times_ptr, align 4
  br label %bb1

bb:                                               ; preds = %bb1
  %18 = load float** %x_ptr, align 4
  %19 = sitofp i32 %my_rank to float
  %20 = getelementptr inbounds float* %18, i32 %i.0
  store float %19, float* %20, align 1
  %21 = add nsw i32 %i.0, 1
  br label %bb1

bb1:                                              ; preds = %bb, %entry
  %i.0 = phi i32 [ 0, %entry ], [ %21, %bb ]
  %22 = icmp slt i32 %i.0, %max_size
  br i1 %22, label %bb, label %bb2

bb2:                                              ; preds = %bb1
  br label %return

return:                                           ; preds = %bb2
  ret void
}

declare noalias i8* @malloc(i32) nounwind

define void @Print_results(%struct.ompi_communicator_t* %io_comm, i32 %my_rank, i32 %min_size, i32 %max_size, i32 %size_incr, i32 %time_array_order, i32 %test_count, double* %times, double* %max_times, double* %min_times) nounwind {
entry:
  %status = alloca %struct.MPI_Status
  %io_process = alloca i32
  %io_rank = alloca i32
  %"alloca point" = bitcast i32 0 to i32
  %0 = call i32 @Get_io_rank(%struct.ompi_communicator_t* %io_comm, i32* %io_process) nounwind
  %1 = call i32 @MPI_Comm_rank(%struct.ompi_communicator_t* %io_comm, i32* %io_rank) nounwind
  %2 = icmp eq i32 %my_rank, 0
  br i1 %2, label %bb, label %bb1

bb:                                               ; preds = %entry
  %3 = load i32* %io_rank, align 4
  %4 = bitcast double* %times to i8*
  %5 = call i32 @MPI_Send(i8* %4, i32 %time_array_order, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_double to %struct.ompi_datatype_t*), i32 %3, i32 0, %struct.ompi_communicator_t* %io_comm) nounwind
  %6 = load i32* %io_process, align 4
  %7 = bitcast double* %max_times to i8*
  %8 = call i32 @MPI_Send(i8* %7, i32 %time_array_order, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_double to %struct.ompi_datatype_t*), i32 %6, i32 0, %struct.ompi_communicator_t* %io_comm) nounwind
  %9 = load i32* %io_process, align 4
  %10 = bitcast double* %min_times to i8*
  %11 = call i32 @MPI_Send(i8* %10, i32 %time_array_order, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_double to %struct.ompi_datatype_t*), i32 %9, i32 0, %struct.ompi_communicator_t* %io_comm) nounwind
  br label %bb1

bb1:                                              ; preds = %bb, %entry
  %12 = load i32* %io_rank, align 4
  %13 = load i32* %io_process, align 4
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %bb2, label %bb15

bb2:                                              ; preds = %bb1
  %15 = bitcast double* %times to i8*
  %16 = call i32 @MPI_Recv(i8* %15, i32 %time_array_order, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_double to %struct.ompi_datatype_t*), i32 -1, i32 0, %struct.ompi_communicator_t* %io_comm, %struct.MPI_Status* %status) nounwind
  %17 = bitcast double* %max_times to i8*
  %18 = call i32 @MPI_Recv(i8* %17, i32 %time_array_order, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_double to %struct.ompi_datatype_t*), i32 -1, i32 0, %struct.ompi_communicator_t* %io_comm, %struct.MPI_Status* %status) nounwind
  %19 = bitcast double* %min_times to i8*
  %20 = call i32 @MPI_Recv(i8* %19, i32 %time_array_order, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_double to %struct.ompi_datatype_t*), i32 -1, i32 0, %struct.ompi_communicator_t* %io_comm, %struct.MPI_Status* %status) nounwind
  %21 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([25 x i8]* @.str3, i32 0, i32 0)) nounwind
  br label %bb4

bb3:                                              ; preds = %bb4
  %22 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([6 x i8]* @.str4, i32 0, i32 0), i32 %size.0) nounwind
  %23 = add nsw i32 %size.0, %size_incr
  br label %bb4

bb4:                                              ; preds = %bb3, %bb2
  %size.0 = phi i32 [ %min_size, %bb2 ], [ %23, %bb3 ]
  %24 = icmp sle i32 %size.0, %max_size
  br i1 %24, label %bb3, label %bb5

bb5:                                              ; preds = %bb4
  %25 = call i32 @putchar(i32 10) nounwind
  %26 = load i32* %io_process, align 4
  %27 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([40 x i8]* @.str5, i32 0, i32 0), i32 %26, i32 %time_array_order) nounwind
  %28 = load %struct._IO_FILE** @stdout, align 4
  %29 = call i32 @fflush(%struct._IO_FILE* %28) nounwind
  %30 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([25 x i8]* @.str6, i32 0, i32 0)) nounwind
  br label %bb7

bb6:                                              ; preds = %bb7
  %31 = getelementptr inbounds double* %times, i32 %i.0
  %32 = load double* %31, align 1
  %33 = fmul double %32, 1.000000e+03
  %34 = sitofp i32 %test_count to double
  %35 = fdiv double %33, %34
  %36 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([6 x i8]* @.str7, i32 0, i32 0), double %35) nounwind
  %37 = add nsw i32 %i.0, 1
  br label %bb7

bb7:                                              ; preds = %bb6, %bb5
  %i.0 = phi i32 [ 0, %bb5 ], [ %37, %bb6 ]
  %38 = icmp slt i32 %i.0, %time_array_order
  br i1 %38, label %bb6, label %bb8

bb8:                                              ; preds = %bb7
  %39 = call i32 @putchar(i32 10) nounwind
  %40 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([25 x i8]* @.str8, i32 0, i32 0)) nounwind
  br label %bb10

bb9:                                              ; preds = %bb10
  %41 = getelementptr inbounds double* %max_times, i32 %i.1
  %42 = load double* %41, align 1
  %43 = fmul double %42, 1.000000e+03
  %44 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([6 x i8]* @.str7, i32 0, i32 0), double %43) nounwind
  %45 = add nsw i32 %i.1, 1
  br label %bb10

bb10:                                             ; preds = %bb9, %bb8
  %i.1 = phi i32 [ 0, %bb8 ], [ %45, %bb9 ]
  %46 = icmp slt i32 %i.1, %time_array_order
  br i1 %46, label %bb9, label %bb11

bb11:                                             ; preds = %bb10
  %47 = call i32 @putchar(i32 10) nounwind
  %48 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([25 x i8]* @.str9, i32 0, i32 0)) nounwind
  br label %bb13

bb12:                                             ; preds = %bb13
  %49 = getelementptr inbounds double* %min_times, i32 %i.2
  %50 = load double* %49, align 1
  %51 = fmul double %50, 1.000000e+03
  %52 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([6 x i8]* @.str7, i32 0, i32 0), double %51) nounwind
  %53 = add nsw i32 %i.2, 1
  br label %bb13

bb13:                                             ; preds = %bb12, %bb11
  %i.2 = phi i32 [ 0, %bb11 ], [ %53, %bb12 ]
  %54 = icmp slt i32 %i.2, %time_array_order
  br i1 %54, label %bb12, label %bb14

bb14:                                             ; preds = %bb13
  %55 = call i32 @puts(i8* getelementptr inbounds ([2 x i8]* @.str10, i32 0, i32 0)) nounwind
  %56 = load %struct._IO_FILE** @stdout, align 4
  %57 = call i32 @fflush(%struct._IO_FILE* %56) nounwind
  br label %bb15

bb15:                                             ; preds = %bb14, %bb1
  br label %return

return:                                           ; preds = %bb15
  ret void
}

declare i32 @Get_io_rank(%struct.ompi_communicator_t*, i32*)

declare i32 @printf(i8* noalias, ...) nounwind

declare i32 @putchar(i32)

declare i32 @fflush(%struct._IO_FILE*)

declare i32 @puts(i8*)
